package org.aldar.bquest.util;

/**
 * Created with IntelliJ IDEA.
 * User: Daria
 * Date: 4/14/13
 * Time: 11:20 PM
 * To change this template use File | Settings | File Templates.
 */
public class ScoreCounter {

    private int mScore = 0;

    private static ScoreCounter instance;

    private ScoreCounter() {

    }

    public static ScoreCounter getInstance() {
        if (instance == null) {
            instance = new ScoreCounter();
        }
        return instance;
    }

    /**
     * 增长分数
     *
     * @param fallCount
     */
    public void addScore(int fallCount) {
        switch (fallCount) {
            case 3:
                this.mScore += 20;
                break;
            case 4:
                this.mScore += 40;
                break;
            case 5:
                this.mScore += 60;
                break;
            case 6:
                this.mScore += 80;
                break;
            case 7:
                this.mScore += 100;
                break;
            case 8:
                this.mScore += 120;
                break;
            default:
                break;
        }
        this.adjustScorePanel();
        /*
        if (this.mScore < 9999999) {
            ResourceManager.getInstance().getScoreText().setText(String.valueOf(this.mScore));
        } else {
            //Toast.makeText(getApplicationContext(), "恭喜你，你通关了！", Toast.LENGTH_LONG).show();
            ResourceManager.getInstance().getScoreBGText().setText("0000000");
            ResourceManager.getInstance().getScoreText().setText("0");
            this.mScore = 0;
            ResourceManager.getInstance().getScoreText().setPosition(295, 336);
        }
        */
    }

    /**
     * 调整分数面板
     */
    public void adjustScorePanel() {
        /*
        if (this.mScore > 9 && (int) ResourceManager.getInstance().getScoreText().getX() == 295) {
            ResourceManager.getInstance().getScoreBGText().setText("00000");
            ResourceManager.getInstance().getScoreText().setPosition(274, 336);
        } else if (this.mScore > 99 && ResourceManager.getInstance().getScoreText().getX() == 274) {
            ResourceManager.getInstance().getScoreBGText().setText("0000");
            ResourceManager.getInstance().getScoreText().setPosition(253, 336);
        } else if (this.mScore > 999 && ResourceManager.getInstance().getScoreText().getX() == 253) {
            ResourceManager.getInstance().getScoreBGText().setText("000");
            ResourceManager.getInstance().getScoreText().setPosition(232, 336);
        } else if (this.mScore > 9999 && ResourceManager.getInstance().getScoreText().getX() == 232) {
            ResourceManager.getInstance().getScoreBGText().setText("00");
            ResourceManager.getInstance().getScoreText().setPosition(211, 336);
        } else if (this.mScore > 99999 && ResourceManager.getInstance().getScoreText().getX() == 211) {
            ResourceManager.getInstance().getScoreBGText().setText("0");
            ResourceManager.getInstance().getScoreText().setPosition(190, 336);
        } else if (this.mScore > 999999 && ResourceManager.getInstance().getScoreText().getX() == 190) {
            ResourceManager.getInstance().getScoreBGText().setText("");
            ResourceManager.getInstance().getScoreText().setPosition(169, 336);
        }
        */
    }

    /**
     * 分数保存
     */
    public void submitScore() {
        //获取姓名
        /*
        LayoutInflater layoutInflater = LayoutInflater.from(this);
        final View submitTextView = layoutInflater.inflate(R.layout.submit, null);
        final EditText mNameEditText = (EditText) submitTextView.findViewById(R.id.edittext_score);
        mNameEditText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mNameEditText.setHint(null);//文本框灰色的提示文字消失
            }
        });
         */
        /*Dialog dialog = new AlertDialog.Builder(this)
                .setTitle("GameOver")
                .setMessage("游戏得分： " + String.valueOf(mScore))
                .setView(submitTextView)
                .setPositiveButton("提  交", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        SQLiteHelper helper = new SQLiteHelper(getApplicationContext());
                        final String name = mNameEditText.getText().toString();
                        if (name.equals("") || name.trim().equals("")) {
                            Toast.makeText(getApplicationContext(), "名字不能为空！", Toast.LENGTH_LONG).show();
                            submitScore();
                        } else if (helper.isNameExist(name)) {
                            Toast.makeText(getApplicationContext(), "该名已经存在！", Toast.LENGTH_LONG).show();
                            submitScore();
                        } else {
                            final int model;
                            if (mGameModel.equals("timed")) {
                                model = 1;
                            } else {
                                model = 0;
                            }
                            final String rank = helper.queryrank(String.valueOf(mScore), model);
                            helper.insertData(name, mScore, model, Integer.parseInt(rank) + 1);//插入排行榜数据库
                            dialog.cancel();
                            toMenuView();

                        }

                    }
                })
                .setNeutralButton("取  消", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        //toMenuView();
                    }
                })
                .create();
        dialog.show();      */
    }

    public int getScore() {
        return mScore;
    }

    public void setScore(int score) {
        this.mScore = score;
    }


}
